package com.gzk.system.controller;

import com.gzk.basic.util.AjaxResult;
import com.gzk.basic.util.PageList;
import com.gzk.system.domain.Systemdictionarytype;
import com.gzk.system.query.SystemdictionarytypeQuery;
import com.gzk.system.service.ISystemdictionarytypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/type")
@Api(tags = "字典类型接口",description = "字典类型接口详细描述")
public class SystemdictionarytypeController {

    //注入
    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;

    @GetMapping("/{id}")
    public Systemdictionarytype getById(@PathVariable("id") Long id){
        return systemdictionarytypeService.queryById(id);
    }

    @GetMapping("/list")
    public List<Systemdictionarytype> getAll(){
        return systemdictionarytypeService.queryAll();
    }

    @PostMapping("/page")
    public PageList<Systemdictionarytype> pageQuery(@RequestBody SystemdictionarytypeQuery query){
        return systemdictionarytypeService.queryPage(query);
    }

    @ApiOperation(value = "员工添加或修改",notes = "如果有id就是修改否则就是添加")
    @PostMapping("/save")
    public AjaxResult saveOrUpdate(@RequestBody Systemdictionarytype systemdictionarytype){
        try {
            //判断
            if(systemdictionarytype.getId() == null){
                //增加
                systemdictionarytypeService.add(systemdictionarytype);
            }else {
                //修改
                systemdictionarytypeService.update(systemdictionarytype);
            }
            //成功
            return AjaxResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            //失败
            return AjaxResult.ok().setSuccess(false).setMessage("系统繁忙！！");
        }
    }

    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            systemdictionarytypeService.remove(id);
            return AjaxResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            //失败
            return AjaxResult.ok().setSuccess(false).setMessage("系统繁忙！！");
        }
    }

    @PatchMapping("/batch")
    public AjaxResult deleteMany(@RequestBody List<Long> ids){
        try {
            systemdictionarytypeService.removeMany(ids);
            return AjaxResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            //失败
            return AjaxResult.ok().setSuccess(false).setMessage("系统繁忙！！");
        }
    }


}
